window.onload = function() {
	var token = sessionStorage.getItem('token');
	var useraccount = JSON.parse(token).useraccount;
	var userid = JSON.parse(token).id;
	var pieChart6 = echarts.init(document.getElementById('pieChart-6'));
	loadpieChart6();
	option = {
		tooltip: {
			trigger: 'item',
			//      formatter: "{a} <br/>{b}: {c} ({d}%)"
		},
		grid: {
			left: '0',
			right: '0',
			bottom: '0',
			top: '100',
			containLabel: true
		},
		legend: {
			orient: 'vertical',
			left: 0,
			bottom: 0,
			data: ['已用时间', '剩余时间']
		},
		series: [{
			type: 'pie',
			radius: ['46%', '60%'],
			hoverAnimation: false, //是否开启 hover 在扇区上的放大动画效果。
			avoidLabelOverlap: false,
			labelLine: {
				normal: {
					show: false
				}
			},
			data: [{
					value: "65",
					name: '剩余时间',
					label: {
						normal: {
							show: false,
							position: 'center'
						},
					},
					itemStyle: {
						color: '#d7d7d7'
					},
				},
				{
					value: "35",
					name: '已用时间',
					label: {
						normal: {
							show: true,
							position: 'center'
						},
					},
					itemStyle: {
						normal: {
							color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{

									// 0% 处的颜色   
									offset: 0,
									color: '#d63a3b'
								},
								{
									// 100% 处的颜色
									offset: 1,
									color: '#e06742'
								}
							], false)
						}
					},
				},
			]
		}]
	};

	pieChart6.setOption(option);

	
	//ajax数据加载
	function loadpieChart6() {
		var data = JSON.stringify({
			'useraccount': useraccount,
		});

		$.ajax({
			type: "post",
			url: 'http://139.224.208.224:8080/qi-radar/recharge/getFlowUse',
			dataType: 'json',
			contentType: "application/json ",
			data: data,
			success: function(data) {
				if(data.code == 0) {
					var data = data.data;
					pieChart6.setOption({
						series: [{
							data: [
								{
									value: data.leftday,
									name: '剩余时间',
									label: {
										normal: {
											show: false,
											position: 'center'
										},
									},
										itemStyle: {
											color: '#d7d7d7'
										},
									},
								{
									value: data.useday,
									name: '已用时间',
									label: {
										normal: {
											show: true,
											position: 'center'
										},
									},
									itemStyle: {
										normal: {
											color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
													offset: 0,
													color: '#d63a3b'
												},
												{
													offset: 1,
													color: '#e06742'
												}
											], false)
										}
									},
								},
							],
						}]
					});

				} 
//				else {
//					alert(data.errMsg)
//				};
			}
		});

	};
}